#include "stdio.h"
#include "time.h"
#include <math.h>
clock_t start,stop;
double duration;
double f1(int n)
{
	int i,flag,j,sum=0;
	for(i=2;i<=n;i++)//i=2时候开运行到n，1不是素数
		//输入n=1的时候,判断条件i>n,不满足条件，不执行循环
	{
		flag=1;
		for(j=2;j<i;j++)
		{
			if(i%j==0)
				flag=0;
		}
		if(flag==1)sum++;
	}
	return sum;
}
 
double f2(int n)
{
	int i,j,flag,k,sum=0;
 
	if(n>=2)sum+=1;
	for(i=3;i<=n;i++)
	{
		flag=1;
		k=sqrt(i);
		for(j=2;j<=k;j++)
		{
			if(i%j==0)
				{
					flag=0;
					break;
			}
		}
		if(flag==1)sum++;
	}
	return sum;
 
}
 
int main()
{
  int n;
  printf("输入一个正整数n:");
   scanf("%d",&n);
  start=clock();f1(n);
  stop=clock();
  duration=(double)(stop-start)/CLK_TCK;
  printf("ticks1=%f\n",(double)(stop-start));
  printf("duration1=%6.2e\n",duration);
  printf("1~%d的素数个数为%.0f\n",n,f1(n));
 
  start=clock();
  f2(n);
  stop=clock();
  duration=(double)(stop-start)/CLK_TCK;
  printf("ticks2=%f\n",(double)(stop-start));
  printf("duration2=%6.2e\n",duration);
  printf("1~%d的素数个数为%.0f",n,f2(n));
  return 1;
}